<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TCP/IP 协议栈深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border: 1px solid rgba(102, 126, 234, 0.3);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .list-item {
            position: relative;
            padding-left: 28px;
            margin-bottom: 12px;
        }
        
        .list-item::before {
            content: '▸';
            position: absolute;
            left: 0;
            color: #667eea;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-fadeInUp">
                TCP/IP 协议栈深度解析
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 max-w-3xl mx-auto animate-fadeInUp" style="animation-delay: 0.2s;">
                探索互联网通信的基石，理解分层架构的智慧
            </p>
            <div class="flex justify-center space-x-8 animate-fadeInUp" style="animation-delay: 0.4s;">
                <div class="text-center">
                    <i class="fas fa-network-wired text-3xl mb-2"></i>
                    <p class="text-sm">网络层协议</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-exchange-alt text-3xl mb-2"></i>
                    <p class="text-sm">传输层协议</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-shield-alt text-3xl mb-2"></i>
                    <p class="text-sm">可靠传输</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">I</span>P 和 TCP 是互联网协议栈中两个不同层次的协议。IP 负责网络层的基本寻址和路由功能，而 TCP 在其上提供了可靠的数据传输服务。IP 层不能解决数据传输的可靠性、顺序、流量和拥塞控制等问题，因此需要 TCP 层来实现这些功能，以保证数据能够正确、可靠地传输到目标设备。这种分层设计允许协议栈中的每一层专注于特定的任务，从而简化了网络通信的复杂性。
            </p>
        </section>

        <!-- Protocol Stack Visualization -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-center text-gradient">协议栈架构图</h2>
            <div class="mermaid">
                graph TB
                    A[应用层] --> B[传输层 - TCP]
                    B --> C[网络层 - IP]
                    C --> D[数据链路层]
                    D --> E[物理层]
                    
                    style A fill:#e0e7ff,stroke:#667eea,stroke-width:2px
                    style B fill:#ddd6fe,stroke:#764ba2,stroke-width:3px
                    style C fill:#ddd6fe,stroke:#764ba2,stroke-width:3px
                    style D fill:#e0e7ff,stroke:#667eea,stroke-width:2px
                    style E fill:#e0e7ff,stroke:#667eea,stroke-width:2px
            </div>
        </section>

        <!-- IP Layer Section -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 section-title">1. IP 层的职责</h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-6 card-hover">
                <p class="text-lg mb-6 text-gray-700">IP 协议位于网络层（第三层），主要负责以下任务：</p>
                
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="text-center">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-map-marker-alt"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2">寻址</h3>
                        <p class="text-gray-600">为每台设备分配一个唯一的 IP 地址</p>
                    </div>
                    
                    <div class="text-center">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-route"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2">路由</h3>
                        <p class="text-gray-600">确定数据包从源设备到目标设备的路径</p>
                    </div>
                    
                    <div class="text-center">
                        <div class="feature-icon mx-auto">
                            <i class="fas fa-puzzle-piece"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-2">分片和重组</h3>
                        <p class="text-gray-600">当数据包超过网络的最大传输单元（MTU）时，IP 协议将其分割成多个片段，并在接收端重组</p>
                    </div>
                </div>
            </div>
            
            <div class="bg-gradient-to-r from-purple-50 to-indigo-50 rounded-2xl p-8 card-hover">
                <h3 class="text-2xl font-bold mb-4 text-purple-800">
                    <i class="fas fa-info-circle mr-2"></i>特点
                </h3>
                <div class="space-y-3">
                    <div class="list-item text-gray-700">
                        <strong>无连接</strong>：IP 不建立连接，不保证数据包的到达顺序，也不提供错误检测和修正。
                    </div>
                    <div class="list-item text-gray-700">
                        <strong>不可靠</strong>：IP 仅负责数据的发送和路由，不关心数据的完整性和顺序。数据包可能丢失、重复或乱序。
                    </div>
                </div>
            </div>
        </section>

        <!-- TCP Layer Section -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 section-title">2. TCP 层的职责</h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-6 card-hover">
                <p class="text-lg mb-6 text-gray-700 indent-8">TCP 协议位于传输层（第四层），它在 IP 层之上，提供了可靠的数据传输服务。TCP 的主要职责包括：</p>
                
                <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                    <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                        <i class="fas fa-handshake text-3xl text-purple-600 mb-3"></i>
                        <h3 class="text-xl font-bold mb-2">连接建立</h3>
                        <p class="text-gray-600">通过三次握手（Three-Way Handshake）建立可靠的连接</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                        <i class="fas fa-check-double text-3xl text-purple-600 mb-3"></i>
                        <h3 class="text-xl font-bold mb-2">数据完整性</h3>
                        <p class="text-gray-600">确保数据的正确性，通过校验和、确认应答和重传机制保证数据在传输过程中没有错误</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                        <i class="fas fa-sort-numeric-up text-3xl text-purple-600 mb-3"></i>
                        <h3 class="text-xl font-bold mb-2">顺序控制</h3>
                        <p class="text-gray-600">通过序列号和确认号确保数据包按照正确的顺序到达目标</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                        <i class="fas fa-tachometer-alt text-3xl text-purple-600 mb-3"></i>
                        <h3 class="text-xl font-bold mb-2">流量控制</h3>
                        <p class="text-gray-600">通过窗口机制调整数据传输速率，防止发送方过快地发送数据导致接收方处理不过来</p>
                    </div>
                    
                    <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                        <i class="fas fa-traffic-light text-3xl text-purple-600 mb-3"></i>
                        <h3 class="text-xl font-bold mb-2">拥塞控制</h3>
                        <p class="text-gray-600">动态调整数据传输速率，以防网络拥堵</p>
                    </div>
                </div>
            </div>
            
            <div class="bg-gradient-to-r from-indigo-50 to-purple-50 rounded-2xl p-8 card-hover">
                <h3 class="text-2xl font-bold mb-4 text-indigo-800">
                    <i class="fas fa-star mr-2"></i>特点
                </h3>
                <div class="space-y-3">
                    <div class="list-item text-gray-700">
                        <strong>有连接</strong>：TCP 在数据传输之前建立连接，确保双方的通信链路已经准备好。
                    </div>
                    <div class="list-item text-gray-700">
                        <strong>可靠</strong>：提供数据的完整性检查、重传机制、流量控制和拥塞控制，确保数据按序到达并且无误。
                    </div>
                </div>
            </div>
        </section>

        <!-- Why IP Can't Do This -->
        <section class="mb-12">
            <h2